package com.xiaomage.view.draw13

import android.content.Context
import android.graphics.*
import android.view.View

/**
 * Created by Administrator on 2018/1/10.
 */
class MyView1(context: Context): View(context) {
    private var paint=getPaint()
    private var bitmap= Bitmap.createBitmap(500,
            500,Bitmap.Config.ARGB_8888)
    private var DSTBitmap:Bitmap=makeDST()
    private var SRCBitmap=makeSRC()
    init {
        paint=getPaint()
    }
    override fun onDraw(canvas: Canvas) {
        super.onDraw(canvas)
        /*val c=Canvas(bitmap)
        c.drawText("XIAOMAGE",0f,100f,paint)
        canvas.drawBitmap(bitmap,0f,0f,paint)*/
      // canvas.drawBitmap(DSTBitmap,0f,0f,paint)



        val layerId=canvas.saveLayerAlpha(0f,0f,500f,400f,
                0x88,Canvas.ALL_SAVE_FLAG)
        paint.color=Color.parseColor("#fc4c4f")
        canvas.drawRect(0f,0f,150f,160f,paint)
        canvas.restoreToCount(layerId)


    }
    private fun makeDST():Bitmap{
        val bitmap=Bitmap.createBitmap(300,300,Bitmap.Config.ARGB_8888)
        val c=Canvas(bitmap)
        paint.color=Color.parseColor("#448ced")
        c.drawCircle(100f,100f,100f,paint)
        return bitmap
    }
    private fun makeSRC():Bitmap{
        val bitmap=Bitmap.createBitmap(
                300,300,Bitmap.Config.ARGB_8888
        )
        val c=Canvas(bitmap)
        paint.color=Color.YELLOW
        c.drawRect(0f,0f,200f,200f,paint)
        return bitmap
    }


    private fun getPaint():Paint{
        val paint=Paint()
        paint.isAntiAlias=true
        paint.color= Color.RED
        paint.style= Paint.Style.FILL_AND_STROKE
        paint.strokeWidth=5f
        paint.textSize=45f
        return paint
    }
}